package text5;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class frame extends JFrame{
    public frame(){
        frame();
        input();
        this.setVisible(true);
    }
    public void frame(){
        this.setTitle("点击");
        this.setSize(500,550);
        this.setDefaultCloseOperation(3);//关闭方法
        this.setAlwaysOnTop(true);//最上方
        this.setLocationRelativeTo(null);//居中
        this.setLayout(null);//默认容器
    }
    public void input(){
        TextField field = new TextField();
        field.setBounds(20,20,200,30);
        this.getContentPane().add(field);
        JTextArea area = new JTextArea();
        area.setBounds(20,70,300,150);
        this.getContentPane().add(area);
       field.addTextListener(new TextListener() {
           @Override
           public void textValueChanged(TextEvent e) {
               area.setText(field.getText());
           }
       });
        field.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {

            }

            @Override
            public void keyPressed(KeyEvent e) {

            }

            @Override
            public void keyReleased(KeyEvent e) {
                if (e.getKeyCode() == 10){
                    area.setText("");
                }
            }
        });
    }
}
public class Num2 {
    public static void main(String[] args) {
        frame f = new frame();
    }
}
